package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysAnswerConvert;
import net.learn.system.convert.SysFillConvert;
import net.learn.system.dao.SysAnswerDao;
import net.learn.system.entity.SysAnswerEntity;
import net.learn.system.entity.SysFillEntity;
import net.learn.system.query.SysAnswerQuery;
import net.learn.system.query.SysFillQuery;
import net.learn.system.service.SysAnswerService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysAnswerVO;
import net.learn.system.vo.SysFillVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 李立志
 * @since 2022-04-01
 */
@Service
public class SysAnswerServiceImpl extends BaseServiceImpl<SysAnswerDao, SysAnswerEntity> implements SysAnswerService {
    @Override
    public Boolean addAnswer(SysAnswerVO vo){
        SysAnswerEntity entity = SysAnswerConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        return baseMapper.insert(entity)>0;
    }
    @Override
    public Boolean updateAnswer(SysAnswerVO vo){
        SysAnswerEntity entity = SysAnswerConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {

        removeByIds(idList);
    }
    @Override
    public List<SysAnswerVO> qryAnswerList() {

        QueryWrapper queryWrapper = new QueryWrapper();
        return baseMapper.selectList(queryWrapper);
    }
    @Override
    public List<SysAnswerVO> qryPaperAnswerList(SysAnswerQuery qry) {

        return baseMapper.qryPaperAnswerList(qry);
    }
    @Override
    public List<SysAnswerVO> qryAnswerRandList(SysAnswerQuery qry) {

        return baseMapper.qryAnswerRandList(qry);
    }
    @Override
    public List<SysAnswerVO> qryPaperAnswerCondition(SysAnswerQuery qry) {

        return baseMapper.qryPaperAnswerCondition(qry);
    }
    @Override
    public PageResult<SysAnswerVO> qryAnswerListPage(SysAnswerQuery query) {
        IPage<SysAnswerEntity> page = baseMapper.qryAnswerListPage(getPage(query), query);

        return new PageResult<>(SysAnswerConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
    @Override
    public PageResult<SysAnswerVO> qryQuestionAnswer(SysAnswerQuery query) {
        IPage<SysAnswerEntity> page = baseMapper.qryQuestionAnswer(getPage(query), query);

        return new PageResult<>(SysAnswerConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
